<?php
/**
 * 系统的宝藏
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019-03-28
 * Time: 下午 11:26
 */
namespace App;
use Model\TreasureMod;

class Treasure extends Action
{
	private $Treasure = null;

	public function __construct()
	{
		parent::__construct();
		$this->Treasure = new TreasureMod();
	}

	/**
	 * 添加系统宝藏
	 * data.name宝藏名字
	 *data.icon宝藏图标
	 */
	public function add()
	{
		$this->_gpc['data']['uniacid'] = $this->_uniacid;
		if($this->Treasure->insert($this->_gpc['data'])) $this->_result = array('status'=>'success');
		$this->result($this->_result);
	}

	/**
	 * 获取宝藏列表总数
	 */
	public function total()
	{
		$_total = $this->Treasure->total(array('uniacid'=>$this->_uniacid,'status'=>1));
		$this->_result = array('status'=>'success','data'=>$_total);
		$this->result($this->_result);
	}

	/**
	 * 系统宝藏列表
	 * limit
	 */
	public function li()
	{
		$_limit = array();
		if(isset($this->_gpc['limit'])) $_limit = $this->_gpc['limit'];
		$_list = $this->Treasure->findAll(array('uniacid'=>$this->_uniacid,'status'=>1),array('order'=>array('id','desc'),'limit'=>$_limit),array('id','name','icon'));
		if(count($_list)>0){
			foreach($_list as $_k=>$_v){
				$_list[$_k]['icon_url'] = tomedia($_v['icon']);
			}
			$this->_result = array('status'=>'success','data'=>$_list);
		}
		$this->result($this->_result);
	}

	/**
	 * 删除宝藏
	 * treasure_id
	 */
	public function delete()
	{
		if($this->Treasure->update(array('status'=>0),array('id'=>$this->_gpc['treasure_id']))){
			$this->_result = array('status'=>'success');
		}
		$this->result($this->_result);
	}
}